<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Heterogeneous Propagation Medium Example (k-Wave)</title>
	<link rel="stylesheet" href="kwavehelpstyle.css" type="text/css">
	<meta name="description" content="Heterogeneous Propagation Medium Example.">
</head>

<body><div class="content">

<h1>Heterogeneous Propagation Medium Example</h1>

<p>This example provides a simple demonstration of using k-Wave for the simulation and detection of the pressure field generated by an initial pressure distribution within a two-dimensional heterogeneous propagation medium. It builds on the <a href="example_ivp_homogeneous_medium.html">Homogeneous Propagation Medium Example</a>.</p>

<p>
    <ul>
        <li><a href="matlab:edit([getkWavePath('examples') 'example_ivp_heterogeneous_medium.m']);" target="_top">Open the file in the MATLAB Editor</a></li>
        <li><a href="matlab:run([getkWavePath('examples') 'example_ivp_heterogeneous_medium']);" target="_top">Run the file in MATLAB</a></li>
    </ul>
</p>

<h2>Contents</h2>
<div>
	<ul>
        <li><a href="#heading2">Defining a heterogeneous medium</a></li>
        <li><a href="#heading3">Running the simulation</a></li>
    </ul>
</div>

<a name="heading2"></a>
<h2>Defining a heterogeneous medium</h2>

<p>For a homogeneous propagation medium, the sound speed is specified as a single scalar value in SI units. If the propagation medium is heterogeneous, <code>medium.sound_speed</code> and <code>medium.density</code> are instead given as matrices with the same dimensions as the computational grid (i.e., with <code>Nx</code> rows and <code>Ny</code> columns). These matrices can be created in several fashions, including explicitly (as given below), from external image maps, or using spatial or volume data from other simulations or experimental imaging modalities.</p>

<pre class="codeinput">
<span class="comment">% define the properties of the propagation medium</span>
medium.sound_speed = 1500 * ones(Nx, Ny);   <span class="comment">% [m/s]</span>
medium.sound_speed(1:Nx/2, :) = 1800;       <span class="comment">% [m/s]</span>
medium.density = 1000 * ones(Nx, Ny);       <span class="comment">% [kg/m^3]</span>
medium.density(:, Ny/4:Ny) = 1200;          <span class="comment">% [kg/m^3]</span>
</pre>

<a name="heading3"></a>
<h2>Running the simulation</h2>

<p>The computation is again invoked by calling <code><a href="kspaceFirstOrder2D.html">kspaceFirstOrder2D</a></code> with the inputs defined above. Rather than manually producing a plot of the initial pressure distribution, sensor mask, and medium properties, it is also possible to use the inbuilt plotting functionality of <code><a href="kspaceFirstOrder2D.html">kspaceFirstOrder2D</a></code> by setting the optional input <code>'PlotLayout'</code> to <code>true</code>. This produces a plot of the simulation inputs as shown below. Optional inputs for k-Wave functions are given after the main inputs as <code>'string'</code>, <code>value</code> pairs. The <code>'string'</code> identifies the optional input parameter that is being modified, and the <code>value</code> is the user setting for this parameter. To remove the PML from the display, the optional input <code>'PlotPML'</code> is also set to <code>false</code>.</p>

<pre class="codeinput">
<span class="comment">% run the simulation with optional inputs for plotting the simulation
% layout in addition to removing the PML from the display</span>
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, ...
    'PlotLayout', true, 'PlotPML', false);
</pre>

<img vspace="5" hspace="5" src="images/example_ivp_heterogeneous_medium_01.png" style="width:560px;height:420px;" alt="">

<p>A plot of the recorded time series is given below. The shape of the main wave-front has been perturbed compared to the homogeneous example, and weak reflections from the heterogeneous interfaces can also be seen.</p>

<img vspace="5" hspace="5" src="images/example_ivp_heterogeneous_medium_02.png" style="width:560px;height:420px;" alt="">
    
</div></body></html>